<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>辅助功能页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layuis/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../res/layuis/dist/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/login_common.js" charset="UTF-8"></script>
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });
        function getQueryString(name){
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]);
            return null;
        }
        var attachTypeId = getQueryString("attachTypeId");
        console.log("辅助功能类型:"+attachTypeId);
    </script>
</head>
<body>

<form class="layui-form layui-header" action="" lay-filter="example">
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <select id="searchCondition" lay-filter="condition">
                <option value="0">请选择查询条件</option>
                <option value="1" >标题</option>
                <option value="2">备注</option>
                <option value="4">发布人</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <input type="text" id="keyword" placeholder="关键字" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="beginTime" class="layui-input test-item" placeholder="起始时间">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="endTime" class="layui-input test-item" placeholder="结尾时间">
        </div>
        <div class="layui-input-inline">
                <a class="layui-btn layui-bg-blue  " lay-event="search" id="search">查询</a>
        </div>
    </div>
</form>
<table class="layui-hide" id="demo" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">浏览</a>
</script>
<script type="text/html" id="toolbarDemo">
</script>

<script type="text/html" id="tempLetState">
    {{#  if(d.auditState == 10){ }}
        <span>通过</span>
    {{#  } else if(d.auditState == 20){ }}
        <span>等待审核</span>
    {{#  } else if(d.auditState == 25){ }}
        <span>未通过</span>
    {{#  } }}
</script>

<script>

    layui.config({
        version: '1572350921010' //为了更新 js 缓存，可忽略
    });

    layui.use([ 'layer', 'table', 'element', 'laydate','form'], function(){
        var layer = layui.layer //弹层
            ,table = layui.table //表格
            ,element = layui.element //元素操作
            ,form = layui.form
            ,laydate = layui.laydate; //表单


        laydate.render({
            elem: '#beginTime'
            ,isInitValue: true
        });
        laydate.render({
            elem: '#endTime'
            ,isInitValue: true
        });

        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.tips('切换了 '+ data.index +'：'+ this.innerHTML, this, {
                tips: 1
            });
        });
        var userId = window.loginObj.manager.usId;
        var userName = window.loginObj.manager.usName;
        var url = "../../attachment/selectTypeAll";
        //执行一个 table 实例
        table.render({
            elem: '#demo'
            //,height: 570
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            ,page: true //开启分页
            ,toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,where:{
                attachType:attachTypeId
                ,userId: userId
                ,userName:userName
            }
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'attachId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'attachName', title: '标题', width:120}
                ,{field: 'attachContent', title: '内容'}
                ,{field: 'attachTime', title: '发布时间', width:120, sort: true}
                ,{field: 'attachValidTime', title: '有效时间', width: 120, sort: true}
                ,{field: 'attachPublisher', title: '发布人', width:120}
                ,{field: 'auditState', title: '审核状态', width: 100, templet: '#tempLetState'}
                ,{field: 'remark', title: '备注', width: 120}
                ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]]
        });

        //下拉列表框点击事件
        form.on('select(condition)', function (data) {
            var searchCondition = $("#searchCondition").val();
            console.log("================"+searchCondition);
        });

        //搜索框点击事件
        $("#search").on("click",function () {
            var searchCondition = $("#searchCondition").val();
            var keyword = $("#keyword").val();
            var auditStatus = $("#auditStatus").val();
            var beginTime = $("#beginTime").val();
            var endTime = $("#endTime").val();
                table.reload('demo',{
                    url: url //数据接口
                    ,where:{
                        searchCondition:searchCondition,
                        keyword:keyword,
                        auditStatus:auditStatus,
                        beginTime:beginTime,
                        endTime:endTime
                    }
                    ,page:{
                        page : 1
                    }
                });
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            var deleteAttachIds = ''; //数组id
            if(layEvent === 'detail'){
                layer.open({
                    type: 2,
                    title : '通知页面',
                    shadeClose : true,
                    shade : 0.8,
                    area : [ '100%', '100%' ],
                    content: 'AttachmentShow.html',
                    success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                        //console.log('============'+iframeWin);
                        body.find("#attachId").val(data.attachId);
                        body.find("#attachType").val(data.attachType);
                        iframeWin.beginShow();
                    },
                    end : function() {
                        //table.reload('demo',{});
                    }
                });
            }
        });

    });


</script>
</body>
</html>